<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/headeradmin.php");
?>

<section>
<hgroup>
<h1>Gebruiker activeren</h1>
</hgroup>
<?php 
    if (isset($_POST["bevestiging"]))
    {
        // Gets the firstname, lastname and email of the user that's going to be activated
        $user = GetUserById($_POST["id"]);
        while ($userRow = mysql_fetch_array($user)){
            $name = $userRow['@firstname']. " " . $userRow['@lastname'] . " (" .$userRow['@email']. ")";
        }
        
        // Activates the selected user
        $resultUpdateUserActivated = UpdateUserActivated($_POST["id"], "T");
        if ($resultUpdateUserActivated == 1)
        {
            echo ("<p>Gebruiker " .$name . " is geactiveerd<br>\n");
            echo ("<a href=\"gebruikers.php\">Terug naar het overzicht van gebruikers.</a></p>");
        }
    }
    else
    {
        // A check if the id is still a numeric character and hasn't been changed manually
        if (!is_numeric($_GET['id'])) { 
            header("Location: ".$cfg['basepath']."controller/gebruiker/gebruikers.php");
        }

        // Gets the data from the selected user
        $user = GetUserById($_GET["id"]);
        while ($userRow = mysql_fetch_array($user)){
            echo "<p>Voornaam = " . $userRow['@firstname'] . "<br>\n";
            echo "Achternaam = ". $userRow['@lastname'] . "<br>\n";
            echo "Email = ". $userRow['@email'] . "</p>";
        }
?>
<form action="<?php echo($_SERVER["PHP_SELF"]);?>" method="post">
    <p>
        <input type="hidden" name="bevestiging" value="1" />
        <input type="hidden" name="id" value="<?php echo($_GET["id"]);?>" />
        <input type="submit" value="Ja, activeren" />
        <input type="button" value="Nee, terug" onclick="javascript:history.back();" />
    </p>
</form>
<?php
    }
?>
</section>

<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/footer.php");
?>